package com.care.mall.server.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.care.common.log.annotation.Log;
import com.care.common.log.enums.BusinessType;
import com.care.common.security.annotation.RequiresPermissions;
import com.care.mall.common.domain.MallBusiness;
import com.care.mall.server.service.IMallBusinessService;
import com.care.common.core.web.controller.BaseController;
import com.care.common.core.domain.Result;
import com.care.common.core.utils.poi.ExcelUtil;
import com.care.common.core.web.page.TableDataInfo;

/**
 * 商家信息Controller
 *
 * @author 李光耀负责
 * @date 2024-03-27
 */
@RestController
@RequestMapping("/business")
public class MallBusinessController extends BaseController
{
    @Autowired
    private IMallBusinessService mallBusinessService;

    /**
     * 查询商家信息列表
     */
    @RequiresPermissions("mall:business:list")
    @GetMapping("/list")
    public TableDataInfo list(MallBusiness mallBusiness)
    {
        startPage();
        List<MallBusiness> list = mallBusinessService.selectMallBusinessList(mallBusiness);
        return getDataTable(list);
    }

    /**
     * 导出商家信息列表
     */
    @RequiresPermissions("mall:business:export")
    @Log(title = "商家信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallBusiness mallBusiness)
    {
        List<MallBusiness> list = mallBusinessService.selectMallBusinessList(mallBusiness);
        ExcelUtil<MallBusiness> util = new ExcelUtil<MallBusiness>(MallBusiness.class);
        util.exportExcel(response, list, "商家信息数据");
    }

    /**
     * 获取商家信息详细信息
     */
    @RequiresPermissions("mall:business:query")
    @GetMapping(value = "/{businessId}")
    public Result getInfo(@PathVariable("businessId") Long businessId)
    {
        return success(mallBusinessService.selectMallBusinessByBusinessId(businessId));
    }

    /**
     * 新增商家信息
     */
    @RequiresPermissions("mall:business:add")
    @Log(title = "商家信息", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody MallBusiness mallBusiness)
    {
        return toAjax(mallBusinessService.insertMallBusiness(mallBusiness));
    }

    /**
     * 修改商家信息
     */
    @RequiresPermissions("mall:business:edit")
    @Log(title = "商家信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody MallBusiness mallBusiness)
    {
        return toAjax(mallBusinessService.updateMallBusiness(mallBusiness));
    }

    /**
     * 删除商家信息
     */
    @RequiresPermissions("mall:business:remove")
    @Log(title = "商家信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{businessIds}")
    public Result remove(@PathVariable Long[] businessIds)
    {
        return toAjax(mallBusinessService.deleteMallBusinessByBusinessIds(businessIds));
    }
}
